package api

import (
	"github.com/gin-gonic/gin"
	"guard/internal/app/admin/service"
	"guard/internal/app/admin/store"
	"guard/internal/db"
	"guard/internal/middleware"
)

var adminService service.AdminService

func init() {
	adminService = service.NewClientService(store.NewAdminStore(db.NewMySqlStore()))
}

func InitAdminRouter(router *gin.Engine) {

	// 客户端注册
	router.POST("register_client", middleware.AuthLoginJson, middleware.ErrJsonHandler, registerClient)
	// 查询客户端
	router.GET("apply_client", middleware.AuthLoginJson, middleware.ErrJsonHandler, applyClient)
	// 删除客户端
	router.POST("del_app", middleware.AuthLoginJson, middleware.ErrJsonHandler, delClient)

	// 后台
	admin := router.Group("admin", middleware.ErrJsonHandler, middleware.TokenAuth("SYS:OAUTH:ALL"))
	{
		client := admin.Group("client")
		{
			client.GET("", clientPage)
			client.GET("/:query", queryClient)
			client.POST("add", addClient)
			client.DELETE("/:client_id", removeClient)
		}

		scope := admin.Group("scope")
		{
			scope.GET("/all", scopeAll)
			scope.GET("", scopePage)
			scope.GET("/:query", queryScope)
			scope.POST("add", addScope)
			scope.DELETE("/:tag", removeScope)
		}
	}

	return
}
